import { request } from '@/base/Request';
import { SeftMotion } from '@/base/model/SeftMotion'
import { SalesRecords } from '@/base/model/SalesRecords'
import { Maintenance } from '@/base/model/Maintenance'
import qs from 'qs'

export function postSeftMotion(params: {
  
  describe: string,
  extName: string,
  iconUrl: string,
  selectedIconUrl: string,
  backgroundUrl: string,
  appUrl: string,
  modeName: string,
  modeNameEn: string,
  sn: string,
  modelId: number,
  sortId: number,
  url: string,
  issueStatus: string,
  text: string,
  classification: string,
  describeEn:string
}) {
  return request.post(SeftMotion, '/api/self-motion', qs.stringify(params))
}

export function getSeftMotion(params: {
  pageIndex: number,
  pageSize: number,
  sortDirection: string,
  accountName?: string,
  versions?: string,
  issueStatus?: string,
  modelId: number
}) {
  return request.getPage(SeftMotion, '/api/self-motion', { params })
}

export function getVersions() {
  return request.getArray(String, '/api/self-motion/version')
}

export function getSeftMotionId(
  id: number
) {
  return request.get(SeftMotion, `/api/self-motion/${id}`)
}

export function PutSeftMotionId(params: {
  describe: string,
  describeEn:string
  extName: string,
  iconUrl: string,
  selectedIconUrl: string,
  backgroundUrl: string,
  appUrl: string,
  id: number,
  issueStatus: string,
  modeName: string,
  modeNameEn: string,
  sn: string,
  modelId: number,
  sortId: number,
  url: string,
  text: string,
  classification: string,
}) {
  return request.put(SeftMotion, `/api/self-motion/${params.id}`, qs.stringify(params))
}

export function deleteSeftMotionId(
  id: number
) {
  return request.delete(`/api/self-motion/${id}`)
}

export function getModelSelfMotionByDeviceSn(
  deviceSn: string
) {
  return request.getArray(SeftMotion, `/api/self-motion/deviceSn/${deviceSn}`);
}
export function getModelSelfMotionDownloadedByDeviceSn(
  deviceSn: string
) {
  return request.getArray(SeftMotion, `/api/self-motion/downloaded/${deviceSn}`);
}
//获取销售记录
export function selectByDeviceId(
  deviceId: number
) {
  return request.get(SalesRecords, `/api/sales/selectByDeviceId?deviceId=${deviceId}`);
}
//获取部件寿命
export function getMaintenanceTips(
  deviceSn: String
) {
  return request.getArray(Maintenance, `/api/component-maintenance/MaintenanceTips/${deviceSn}`);
}
//更新销售记录
export function postSalesRecords(params: {
  id: number,
  buyTime: Date,
  deviceId: number,
  customName: string,
  customPhone: string,
  address: string,
  startTime: Date,
  endTime: Date,
  salesName: string,
  salesPhone: string,
}) {
  return request.post(SalesRecords, `/api/sales`, qs.stringify(params))
}
